/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package application;

import controleur.ConnexionBD;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

/**
 *
 * @author James
 */
public class AuteurDAO {
    private static PreparedStatement pstmt;
    private static ResultSet results;
    
    public static ResultSet getAuteurs() {
        final String query = "select * from auteur order by nom_de_famille";
        
        try {          
            pstmt = ConnexionBD.creerConnexion().prepareStatement(query);
            results = pstmt.executeQuery();
            
        } catch (Exception e) {
            return null;
        }
        return results;
    }
    
    public static ResultSet getAuteur(final String idAuteur) {
        final String query = "select * from auteur where id_auteur=?";
        
        try {          
            pstmt = ConnexionBD.creerConnexion().prepareStatement(query);
            pstmt.setInt(1, Integer.parseInt(idAuteur));
            results = pstmt.executeQuery();
            
        } catch (Exception e) {
            return null;
        }
        return results;
    }
    
    public static ResultSet getAuteurLivre(final String isbn) {
        final String query = "select * from auteur a join auteur_livre al on a.id_auteur=al.id_auteur join livre l on al.isbn=l.isbn "
                + "where l.isbn=?";
        
        try {          
            pstmt = ConnexionBD.creerConnexion().prepareStatement(query);
            pstmt.setString(1, isbn);
            results = pstmt.executeQuery();
            
        } catch (Exception e) {
            return null;
        }
        return results;
    }
}
